package edu.ua.bmr.android;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.provider.BaseColumns;

public class BMR {

	public static final String DB_NAME = "BMR";
	public static final String DB_TABLE_USERS = "Users";
	public static final int DB_VERSION = 1;
	public static final String TEXT_FORMAT = "UTF-8";
	
	/**
	 * The following constants are some keywords we are expecting 
	 * when the server responds to us. When referencing a table field,
	 * we name its constant TABLE_[Tablename]_[Fieldname].
	 * 
	 * KEYWORD prefixes don't correspond to table fields, but are
	 * "miscellaneous other info" the server will provide to us.
	 */
	public static final String KEYWORD_REGISTERED = "registered";
	public static final String KEYWORD_CONFIRMED = "confirmed";
	public static final String KEYWORD_RESULT = "result";
	public static final String KEYWORD_MSG = "msg";
	public static final String TABLE_CLASSES_CRN = "crn";
	public static final String TABLE_CLASSES_CWID = "cwid";
	public static final String TABLE_SEMESTER_ADDABLE = "add";
	public static final String TABLE_SEMESTER_DROPPABLE = "drop";
	public static final String TABLE_SEMESTER_ID = "id";
	public static final String TABLE_SEMESTER_NAME = "name";
	
	public static final String CLASSLIST_FIELDS[] = {"title", "dept", "code", "section", "instructor", "times"};
	public static final int CLASSLIST_VIEWS[] = {R.id.classitem_title, R.id.classitem_department, R.id.classitem_number, R.id.classitem_section, R.id.classitem_instructor, R.id.classitem_time};
	
	public static final class Users implements BaseColumns {
		public static final String USERNAME = "Username";
		public static final String PASSWORD = "Password";
	}
	
	public static Dialog showProgressDialog(Context context, int resTitle, int resMsg) {
		Resources r = context.getResources();
		Dialog d = ProgressDialog.show(context, r.getString(resTitle), r.getString(resMsg));
		d.setCancelable(true);
		return d;
	}
	
	public static Intent getClassViewIntent(Context context, HashMap<String, String> values) {
		// We're sending the user off to ClassActivity land...
		Intent intent = new Intent(context, ClassActivity.class);
		
		// Populate the intent with the key/value set of the HashMap selected.
		Set<String> keySet = values.keySet();
		Iterator<String> iter = keySet.iterator();
		while(iter.hasNext()) {
			String key = iter.next();
			String value = (String) values.get(key);
			intent.putExtra(key, value);
		}
		
		return intent;
	}
}
